%no : nomor soal berdasarkan soal tugas
%A  : matriks data
function [hasil] = mn_newtonk(A, titik_interpolasi, derajat, handles)
%UNTITLED3 Summary of this function goes here
%   Detailed explanation goes here
if (length(A(1,:))==2)          %interpolasi 1 peubah
    X = A(:,1);
    Y = A(:,2);
    disp(X);
    disp(Y);
    
    N = length(X);
    ST = zeros(N, N);
    if(derajat > N) 
        derajat = N;
    end
    
    D = length (X);
    ST2 = 0;
    for j = 1 : D
    ST2 (j) = X(j,1) - titik_interpolasi;
    end
    T = 0;
    for j = 1 : D - 1
        if (ST2(j)*ST2(j+1) <= 0)
            if(abs(ST2(j)) > abs (ST2(j+1)) )
                T = j + 1;
            else
                T = j;
            end
        end
    end
    start = 0;
    if (T == 0)
        start = D - derajat + 1;
    else 
        if (D - T < derajat / 2 )
            start = D - derajat + 1;
        else
            if (T <= derajat / 2 )
                start = 1;
            else
                if (mod(derajat,2) == 0)
                    start = T - (derajat/2) + 1;
                else
                    start = T - (derajat + 1) / 2 + 1;
                end
            end
        end
    end
    
    % simpan f(x) pada kolom pertama ST
    ST(:,1) = Y';
    start
    if (start == 1)
        hasil = mn_newton(A,titik_interpolasi,derajat,handles);
    else
        B = 0;
        i = 1;
        for k = start : length (A)
            B(i,1) = A(k,1);
            B(i,2) = A(k,2);
            i = i+1;
        end
        B
        hasil = mn_newton(B,titik_interpolasi,derajat,handles);
    end
    

    
elseif (length(A(1,:))==3)      %interpolasi 2 peubah
    titik_interpolasi = [15 50];
    X = A(:,1);
    Y = A(:,2);
    Z = A(:,3);
    D = length(X);
    XL = X(1);
    Table1 = 0;
    Table2 = 0;
    k = 1;
    l = 1;
    for i = 1:D
        if (XL ~= X(i))
            Table1
            Table2(k,1)= XL;
            Table2(k,2)= mn_newton(Table1,titik_interpolasi(1,2),derajat, handles);
            XL = X(i);
            l = 1;
            k = k +1;
            Table1 = 0;
        end
        Table1(l,1) = Y(i);
        Table1(l,2) = Z(i);
        l = l + 1;
    end
    Table2
    Table2(k,1)= XL;
    Table2(k,2)= mn_newton(Table1,titik_interpolasi(1,2),derajat, handles);
    Table2;
    hasil = mn_newton(Table2,titik_interpolasi(1,1),derajat, handles);
    
end

